﻿from pycad.system import *
from pycad.runtime import *

@command()
def myss1():
    respt = ed.GetPoint("选择起点")
    if respt.Status != aced.PromptStatus.OK:
        return
    rescor = ed.GetCorner("选择终点", respt.Value)
    if rescor.Status != aced.PromptStatus.OK:
        return
    res = ed.SelectCrossingWindow(respt.Value, rescor.Value, conv.ToFilter([[0, 'line']]))
    if res.Status == aced.PromptStatus.OK:
        ed.SetImpliedSelection(res.Value)

@command()
def myss2():
    with dbtrans() as tr:
        lst = (
            i for i in tr.opencurrspace()
            if i.ObjectClass.DxfName == 'LINE')
        ed.SetImpliedSelection(tuple(lst))

@command()
def comtest():
    res = ed.GetSelection()
    if res.Status == aced.PromptStatus.OK:
        doc = ed.GetAcadDocument()
        try: doc.SelectionSets['NFox.Wmf'].Delete()
        except: pass
        ss = doc.SelectionSets.Add('NFox.Wmf')
        with dbtrans(False) as tr:
            objs = (tr.getobject(i).AcadObject for i in res.Value.GetObjectIds())
            ss.AddItems(conv.ToSafeArray(tuple(objs)))
            doc.Export('d:\\1', 'wmf', ss)